﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DonutLandLibrary.Data
{
    class GeneticProfilesData
    {
        public static GeneticProfile GetGeneticProfile(int ID)
        {
            RobotsEntities entities = new RobotsEntities();

            GeneticProfile geneProfile = entities.GeneticProfiles.Where(gp => gp.ID == ID).FirstOrDefault();

            return geneProfile;
        }

        public static int Save(Robots.GeneticAlgorithm.GeneticProfile geneProfile)
        {
            RobotsEntities entities = new RobotsEntities();

            //create the LINQ DB entity
            GeneticProfile geneticProfile = new GeneticProfile();

            //add the property values
            geneticProfile.ID = geneProfile.ID;
            geneticProfile.EnergyDepletionRate = geneProfile.EnergyDepletionRate;
            geneticProfile.MaximumEnergyDepletionReserve = geneProfile.EnergyDepletionReserve;
            geneticProfile.MaximumEnergyLevel = geneProfile.MaximumEnergyLevel;
            geneticProfile.MaximumProtectiveCasing = geneProfile.MaximumProtectiveCasing;
            geneticProfile.ProtectiveCasingRepairRate = geneProfile.ProtectiveCasingRepairRate;
            geneticProfile.ProtectiveCasingRepairReserve = geneProfile.ProtectiveCasingRepairReserve;

            entities.AddToGeneticProfiles(geneticProfile);

            entities.SaveChanges();

            return geneticProfile.ID;
        }
    }
}
